<?php
class Logs extends Model{

	public function getlog() {
		$u = $this->model('User');
		if(isset($_POST['stime']) && !empty($_POST['stime'])){
			$file = BASE_ROOT . DS . APP_DIR . DS .'Logs'.DS.$_POST['stime'];
		}else{
			$file = BASE_ROOT . DS . APP_DIR . DS .'Logs'.DS.date('Y-m-d',mktime());
		}
		$logs = array();
		$lines = array();
		if(file_exists($file)){
			$lines = file($file);
		}
		foreach($lines as $value){
			$logs[] = explode('|',$value);
		}
		return $logs;
	}
	public function savelog() {
		$this->helper(array('cookie','file'));
		$u = $this->model('User');
		$t = mktime();
		$log = $t.'|'.get_cookie('u_id').'|'.get_cookie('u_name').'|'.json_encode($_GET)."\n";
		$file = BASE_ROOT . DS . APP_DIR . DS .'Logs'.DS;
		if(!is_dir($file)){
			@mkdir($file, 0777);
		}
		$file .= date('Y-m-d',$t);
		write_file($file,$log);
	}
}